package by.exposit.service;

import by.exposit.dao.CommentDAO;
import by.exposit.dao.entity.CommentEntity;
import by.exposit.domain.Comment;
import by.exposit.domain.Project;
import org.dozer.DozerBeanMapperSingletonWrapper;
import org.dozer.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
@Service
 @Transactional
public class CommentServiceImpl implements CommentService{

     @Autowired
     private CommentDAO commentDAO;

    @Override
    public void saveComment(Comment comment) {
        Mapper mapper = DozerBeanMapperSingletonWrapper.getInstance();
        commentDAO.save(mapper.map(comment, CommentEntity.class));

    }

    @Override
    public List<Comment> commentList(Project project) {
        List<Comment> comments  = new ArrayList<Comment>();

        Mapper mapper = DozerBeanMapperSingletonWrapper.getInstance();

        List<CommentEntity> commentEntities = commentDAO.listComments(project);

        for(CommentEntity commentEntity: commentEntities)
        {
            comments.add(mapper.map(commentEntity,Comment.class));
        }
        return comments;
    }

    @Override
    public void remove(Long commentId) {


        commentDAO.remove(commentId);
    }


}
